# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: Rhys Davies <rhys@johnguant.com>

pkgname=ruby-multipart-post
pkgver=2.3.0
pkgrel=1
pkgdesc='A multipart form post accessory for Net::HTTP'
arch=(any)
url='https://github.com/socketry/multipart-post'
license=(MIT)
depends=(ruby)
makedepends=(ruby-rspec ruby-covered)
checkdepends=(ruby-bake ruby-bake-modernize ruby-bake-test ruby-bake-test-external)
options=(!emptydirs)
source=(https://github.com/socketry/multipart-post/archive/v$pkgver/$pkgname-$pkgver.tar.gz)
sha256sums=('006f1fd953eda4d41f4ce03602ab0930e911adb7a1124b5b23b9fbc3c29a601d')

prepare() {
  cd multipart-post-$pkgver
  sed -i -e '/signing_key/d' -e 's/~>/>=/' multipart-post.gemspec
  sed -i '/bake-gem/d' gems.rb
}

build() {
  local _gemdir="$(gem env gemdir)"
  cd multipart-post-$pkgver
  gem build multipart-post.gemspec
  gem install \
    --local \
    --verbose \
    --ignore-dependencies \
    --no-user-install \
    --install-dir "tmp_install/$_gemdir" \
    --bindir "tmp_install/usr/bin" \
    multipart-post-$pkgver.gem
  find "tmp_install/$_gemdir/gems/" \
    -type f \
    \( \
        -iname "*.o" -o \
        -iname "*.c" -o \
        -iname "*.so" -o \
        -iname "*.time" -o \
        -iname "gem.build_complete" -o \
        -iname "Makefile" \
    \) \
    -delete
  rm -r tmp_install/$_gemdir/cache
}

check() {
  local _gemdir="$(gem env gemdir)"
  cd multipart-post-$pkgver
  GEM_HOME="tmp_install/$_gemdir" bake test
}

package() {
  cd multipart-post-$pkgver
  cp -a tmp_install/* "$pkgdir"/
  install -Dm644 license.md -t "$pkgdir"/usr/share/licenses/$pkgname/
}
